/*
 * Copyright (C) 2025 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package top.xbaistack.common;

import lombok.Getter;
import lombok.Setter;

/**
 * WebSocket 中统一响应前端的数据格式
 *
 * <pre>
 *   {"type": "xxx", "data": <Object>}
 * </pre>
 *
 * @author xbaistack
 * @since 2025/03/25
 */
@Getter
@Setter
public class WebSocketResponse {
    private String type;
    private Object data;

    public WebSocketResponse(String type, Object data) {
        this.type = type;
        this.data = data;
    }

    public static WebSocketResponse refresh(Object data) {
        return new WebSocketResponse("refresh", data);
    }

    public static WebSocketResponse unfreeze() {
        return new WebSocketResponse("unfreeze", true);
    }

    public static WebSocketResponse init(Object data) {
        return new WebSocketResponse("init", data);
    }

    public static WebSocketResponse online() {
        return new WebSocketResponse("online", "玩家上线啦~");
    }

    public static WebSocketResponse offline() {
        return new WebSocketResponse("offline", "对面玩家掉线啦！");
    }

    public static WebSocketResponse error(String message) {
        return new WebSocketResponse("error", message);
    }

    public static WebSocketResponse finished(String message) {
        return new WebSocketResponse("finished", message);
    }
}
